using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.Multimedia.Library;
using NCS.Module.Multimedia.Library.Gallery;
using NCS.Library.Utilities;

namespace NCS.Module.Multimedia.Web.Gallery
{

    public partial class FolderGalery : GalleryWebControl 
    {
        protected int start = 0, end = 12, total = 0, page = 0, pagesize = 12;
        private string userUploadPath = Library.Definies.UploadPath;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                page = ConvertUtility.ToInt32(Request["page"], 0);
                total = ConvertUtility.ToInt32(Request["total"], 0);

                if (total > 0) {
                    start = page + pagesize ;
                    end = start + pagesize;
                }

                DataTable tbl = Gallery_AlbumController.GetAllAlbum(start, end, total);

                if (tbl != null && tbl.Rows.Count > 0)
                {
                    total = ConvertUtility.ToInt32(tbl.Rows[0]["total"]);
                }

                dtgPicList.DataSource = tbl;
                dtgPicList.ItemDataBound += new DataListItemEventHandler(dtgPicList_ItemDataBound);
                dtgPicList.DataBind();
            }
        }

        void dtgPicList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemIndex < 0) return;
            DataRowView currow = (DataRowView)e.Item.DataItem;

            string url = BuildUrlByPicInAlbum(ConvertUtility.ToInt32(currow["AlbumID"]));

            HyperLink link_img = (HyperLink)e.Item.FindControl("link_image");
            link_img.NavigateUrl = url;

            HyperLink link_name = (HyperLink)e.Item.FindControl("link_name");
            link_name.NavigateUrl = url;
            link_name.Text = ConvertUtility.ToString(currow["AlbumName"]);
        }
    }
}